/**
 * AuthController
 *
 * @description :: Server-side logic for managing auths
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {
    login:function(req,res){
        let {username,password}=req.body;
        AuthService.login(username,password,(targetPeople)=>{
            req.session.login=targetPeople;
            if(targetPeople.name=='肖驰' || targetPeople.name=='李登富'){
                req.session.authenticated=true;
            }
            res.json({
                success:true,
                data:targetPeople
            });
        },()=>{
            delete req.session.login;
            res.json({
                success:false
            });
        });
        // req.session.authenticated=true;
    },
    logout:function(req,res){
        // req.session.authenticated=false;
        if(req.session.login){
            delete req.session.login;
        }
        res.json({
            success:true
        })
    },
    userInfo:function(req,res){
        // console.log(12345);
        // console.log(req.session);
        if(req.session.login){
            res.json(req.session.login);
        }else{
            res.json(null);
        }
    }
};
